package servlet;

import http.LmyRequest;
import http.LmyResponse;

import java.io.IOException;
import java.io.OutputStream;

public class LmyCalServlet extends LmyHttpServlet {

    @Override
    public void init() throws Exception {

    }

    @Override
    public void doGet(LmyRequest request, LmyResponse response){
        int num1 = Integer.parseInt(request.getParameter("num1"));
        int num2 = Integer.parseInt(request.getParameter("num2"));
        int res = num1 + num2;

        OutputStream outputStream = response.getOutputStream();
        String respMes = LmyResponse.respHeader + "<h1>"+ num1 + "+" + num2 + "=" + res + "<h1/>";
        try {
            outputStream.write(respMes.getBytes());
            outputStream.flush();
            outputStream.close();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public void doPost(LmyRequest request, LmyResponse response) throws Exception {
        this.doGet(request, response);
    }

    @Override
    public void destroy() {

    }


}
